package com.yhgarden.bbs.controller.system;

import com.yhgarden.bbs.entity.system.Entity;
import com.yhgarden.bbs.model.response.BaseResponse;
import com.yhgarden.bbs.service.api.system.EntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping(value = {"/system/entity","*/system/entity"})
public class EntityController {

    @Autowired
    private EntityService entityService;

    /**
     * 创建或者修改实体信息
     * @param entity
     * @return
     */
    @RequestMapping(value = "/createOrUpdate", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse createOrUpdate(@RequestBody Entity entity) {
        BaseResponse res = entityService.createOrUpdate(entity);
        return res;
    }

    @RequestMapping(value = "/getById/{entityId}", method = RequestMethod.GET)
    @ResponseBody
    public BaseResponse getById(@PathVariable("entityId") String entityId) {
        BaseResponse res = entityService.getById(entityId);
        return res;
    }

    @RequestMapping(value = "/getByIdMoreDetail/{entityId}", method = RequestMethod.GET)
    @ResponseBody
    public BaseResponse getByIdMoreDetail(@PathVariable("entityId") String entityId) {
        BaseResponse res = entityService.getByIdMoreDetail(entityId);
        return res;
    }

    @RequestMapping(value = "/query", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse query(@RequestBody Entity entity) {
        BaseResponse res = entityService.query(entity);
        return res;
    }

    @RequestMapping(value = "/queryMoreDetail", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse queryMoreDetail(@RequestBody Entity entity) {
        BaseResponse res = entityService.queryMoreDetail(entity);
        return res;
    }

    @RequestMapping(value = "/queryForList", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse queryForList(@RequestBody Entity entity) {
        BaseResponse res = entityService.queryForList(entity);
        return res;
    }

    @RequestMapping(value = "/delete/{entityId}", method = RequestMethod.POST)
    @ResponseBody
    public BaseResponse delete(@PathVariable("entityId") String entityId) {
        BaseResponse res = entityService.delete(entityId);
        return res;
    }
}
